package com.xbongbong.saas.domain.entity;/*/*/

import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.paas.toolbox.wrap.Entity;
import com.xbongbong.pro.constant.I18nStringConstant;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.context.i18n.LocaleContextHolder;

import java.util.Locale;
import java.util.Objects;

/**
 *
 * @author 魏荣杰
 * @date 2019/3/14 9:56
 * @since v1.0
 * @version v1.0
 */
@Setter
@Getter
@ToString
public class WorkOrderFormEntity extends Entity{
    private static final long serialVersionUID = 1648139489960229675L;

    /**
     * 主键
     */
    private Long id;
    /**
     * 公司id
     */
    private String corpid;
    /**
     * 应用id
     */
    private Long appId;
    /**
     * 菜单id
     */
    private Long menuId;
    /**
     * 表单名称
     */
    private String name;
    /**
     * 表单名称英文版
     */
    private String nameEn;
    /**
     * 启用
     */
    private Integer enable;
    /**
     * 是否流程表单，1是，0否
     */
    private Integer isProcessForm;
    /**
     * 表单验证规则
     */
    private String verifyRule;
    /**
     * 不可见字段赋值，1 保持原值，2 空值，3 始终重新计算
     */
    private Integer disableFieldAssign;
    /**
     * 前端缓存，1 启用，0 禁用
     */
    private Integer frontCache;
    /**
     * 数据标题类型，1第一个字段，2自定义标题
     */
    private Integer titleType;
    /**
     * 自定义标题，具体指定格式
     */
    private String customTitle;

    /**
     * 关联列表设置
     */
    private String associationList;
    /**
     *  业务规则
     */
    private String businessRules;
    /**
     * 自定义摘要，具体指定格式, 用于手机端列表页显示
     */
    private String summary;
    /**
     * 标签列表，最多5个字段
     */
    private String labels;
    /**
     * 协同人权限设置
     */
    private String coOpPerms;
    /**
     * 创建者id
     */
    private String creatorId;
    /**
     * 创建时间时间戳
     */
    private Long addTime;
    /**
     * 更新时间时间戳
     */
    private Long updateTime;
    /**
     * 删除标记
     */
    private Integer del;
    /**
     * 工单模板id
     */
    private Long templateId;

    /**
     * 表单的单位列宽
     */
    private String fieldPosition;

    /**
     * 镜像工单表单id(镜像应用复制时使用)
     */
    private Long mirrorFormId;
    /**
     * 镜像工单菜单id(镜像应用复制时使用)
     */
    private Long mirrorMenuId;

    public WorkOrderFormEntity(){
        del = 0;
    }

    public WorkOrderFormEntity(String corpid, Long appId, Long menuId, String name, Integer enable, Integer isProcessForm, String verifyRule, Integer disableFieldAssign, Integer frontCache, Integer titleType, String customTitle, String associationList, String businessRules, String summary, String labels, String coOpPerms, String creatorId, Long addTime, Long updateTime, Integer del, Long templateId) {
        this.corpid = corpid;
        this.appId = appId;
        this.menuId = menuId;
        this.name = name;
        this.enable = enable;
        this.isProcessForm = isProcessForm;
        this.verifyRule = verifyRule;
        this.disableFieldAssign = disableFieldAssign;
        this.frontCache = frontCache;
        this.titleType = titleType;
        this.customTitle = customTitle;
        this.associationList = associationList;
        this.businessRules = businessRules;
        this.summary = summary;
        this.labels = labels;
        this.coOpPerms = coOpPerms;
        this.creatorId = creatorId;
        this.addTime = addTime;
        this.updateTime = updateTime;
        this.del = del;
        this.templateId = templateId;
    }

    public String getName() {
        Locale locale = LocaleContextHolder.getLocale();
        if (Objects.equals(locale.getLanguage(), I18nStringConstant.ENGLISH_LANGUAGE)&& StringUtil.isNotEmpty(nameEn)) {
            return nameEn;
        }
        return name;
    }

    public String getNameEn() {
        Locale locale = LocaleContextHolder.getLocale();
        if (Objects.equals(locale.getLanguage(), I18nStringConstant.ENGLISH_LANGUAGE)) {
            return name;
        }
        return nameEn;
    }
}
